<?php
include "../../public/config/config.php";
include "../../public/include/funcs.php";
$link=conn($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd,$cfg_dbname,$cfg_dbchar);
$date = date("Ymd");
$arr = select($link, 'diy_hc', "date=".$date);
if(!$arr){
	$re = add($link, 'diy_hc', ['date' => $date, 'num1' => 1]);
	$arr = select($link, 'diy_hc', "date=".$date);
}

$where = '';
foreach($arr[0] as $k=>$v){
	if(preg_match("/num/", $k) && in_array($v, ['1', '2', '3'])){
		// var_dump($v);
		$where .= " and `{$k}`={$v}";
	}
}
$where = trim($where, ' and ');
// select * from stu limit 7,2;
$arr_list = select($link, 'diy_hc', $where." order by id desc limit 4");
foreach($arr_list as $k=>$v){
	if($k == 0){
		continue;
	}
	foreach($v as $kk=>$vv){
		if(preg_match("/num/", $kk)){
			if($vv){
				$ceng = str_replace('num', '', $kk);
				$arr_str[$k] .= $ceng . '-' . $vv . ' ';
			}
		}
	}
	$arr_str[$k] .= '('.$v['date'].')';
}

echo json_encode($arr_str);



// var_dump($where);
// echo "<pre>";
// print_r($arr_str);
// print_r($arr_list);
// echo "</pre>";
?>